package com.itheima.controller;

import com.itheima.domain.Account;
import com.itheima.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/*@Controller
@RequestMapping("/account")
@ResponseBody*/
@RestController
@RequestMapping("/account")
public class AccountController {

    @Autowired
    private AccountService accountService;

    @RequestMapping("/findAllAccount")
    public List<Account> findAllAccount() {
        return accountService.findAll();
    }

    /* 添加一条账户记录 */
    @RequestMapping("/addAccount")
    public void addAccount(Account account) {
        accountService.addAccount(account);
    }

    /* 根据name删除一条记录 */
    @RequestMapping("/delAccount")
    public void delAccount(String accountName) {
        accountService.delAccount(accountName);
    }

    /* 根据名称修改一条记录 */
    @RequestMapping("/updateAccount")
    public void updateAccount(Account account) {
        accountService.updateAccount(account);
    }

    /* 根据名称查询一条记录 */
    @RequestMapping("/findAccountByName")
    public Account findAccountByName(String accountName) {
        return accountService.findAccountByName(accountName);
    }

    /* 转账 */
    @RequestMapping("/transAccount")
    public void transAccount(String formName, String toName, Double money) {
        accountService.transMoney(formName, toName, money);
    }
}
